<template>
  <transition name="panel-slide">
    <div v-if="visible" class="panel-wrapper">
      <div class="panel-container">
        <div class="left-panel">
          <div class="left-panel-content">
            <slot></slot>
          </div>
        </div>
        <div class="right-panel">
          <div class="panel-buttons-wrapper">
            <div class="panel-buttons">
              <button v-for="(layer, index) in panelLayers" :key="layer.id" class="switch-btn"
                :class="{ active: index === currentLayerIndex }" @click="switchPanel(index)">
                {{ layer.name || 'Layer ' + (index + 1) }}
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>
<script>
export default {
  name: 'RightPanel',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    panelLayers: {
      type: Array,
      default: () => []
    },
    activeLayerId: {
      type: String,
      default: ''
    }
  },
  computed: {
    currentLayerIndex() {
      return this.panelLayers.findIndex(layer => layer.id === this.activeLayerId);
    }
  },
  methods: {
    switchPanel(index) {
      this.$emit('switch-layer', this.panelLayers[index]);
    }
  }
};
</script>


<style scoped lang="scss">
.panel-wrapper {
    background-color: #fff;
  position: fixed;
  top: 110px;
  right: 5px;
  min-width: 300px;
  width: fit-content;
  height: calc(100vh - 120px);
  // height:940px;
  z-index: 1000;
  display: flex;
  justify-content: flex-end;

  .panel-container {
    display: flex;
    height: 100%;
    position: relative;

    .left-panel {
      min-width: 300px;
      width: fit-content;
      max-width: 500px;
      height: 100%;
      background-color: #ffffff;
      box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
      display: flex;
      flex-direction: column;
      position: relative;
      z-index: 1;

      .left-panel-content {
        flex: 1;
        overflow-y: auto;
        // padding: 15px 20px;
        width: fit-content;
        background-color: #ffffff;

        // 美化滚动条样式
        &::-webkit-scrollbar {
          width: 8px;
        }

        &::-webkit-scrollbar-track {
          background: #f5f7fa;
          // border-radius: 4px;
        }

        &::-webkit-scrollbar-thumb {
          background: #dcdfe6;
          border-radius: 4px;
          transition: background 0.3s ease;
          border: 2px solid #f5f7fa;
        }

        &::-webkit-scrollbar-thumb:hover {
          background: #c0c4cc;
        }

        // Firefox 兼容性支持
        scrollbar-width: thin;
        scrollbar-color: #dcdfe6 #f5f7fa;
      }
    }

    .right-panel {
      width: 50px;
      position: absolute;
      left: 0;
      // top: 10%;
      height: 80%;
      transform: translateX(-100%);
      z-index: 2;

      .panel-buttons-wrapper {
        height: 100%;
        overflow-y: auto;
        position: relative;

        // 美化滚动条样式
        &::-webkit-scrollbar {
          width: 4px;
        }

        &::-webkit-scrollbar-track {
          background: transparent;
        }

        &::-webkit-scrollbar-thumb {
          background: rgba(0, 0, 0, 0.2);
          transition: background 0.3s ease;
        }

        &::-webkit-scrollbar-thumb:hover {
          background: rgba(0, 0, 0, 0.4);
        }

        // Firefox 兼容性支持
        scrollbar-width: thin;
        scrollbar-color: rgba(0, 0, 0, 0.3) transparent;

        .panel-buttons {
          position: absolute;
          right: 0;
          top: 0;
          transform: translateY(0);
          display: flex;
          flex-direction: column;
          gap: 10px;
          padding: 5px 0px;
          z-index: 3;

          .switch-btn {
            // padding: 15px 0;
            background-color: rgba(255, 255, 255, 0.85);
            border: 1px solid rgba(220, 223, 230, 0.6);
            border-right: none;
            border-radius: 8px 0 0 8px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            color: #666;
            transition: all 0.3s ease;
            white-space: nowrap;
            writing-mode: vertical-lr;
            text-orientation: mixed;
            height: auto;
            min-height: 80px;
            min-width: 40px;
            box-shadow: -2px 0 8px rgba(0, 0, 0, 0.08);

            &:hover {
              background-color: #f8f9fa;
              color: #307EFF;
              box-shadow: -3px 0 12px rgba(24, 144, 255, 0.15);
              transform: translateX(-2px);
            }

            &.active {
              background-color: #307EFF;
              color: white;
              box-shadow: -3px 0 15px rgba(24, 144, 255, 0.3);
              border-color: #1890ff;
              transform: translateX(-4px);
            }
          }
        }
      }
    }
  }
}

/* 面板过渡动画 */
.panel-slide-enter-active,
.panel-slide-leave-active {
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.panel-slide-enter-from,
.panel-slide-leave-to {
  transform: translateX(100%);
  opacity: 0;
}










</style>
